<template>
  <div>
    <MyHeader title="购物车案例"></MyHeader>
    <div class="main">
      <!-- 2.0渲染数据 -->
      <MyGoods v-for="item in list" :key="item.id" :item="item"></MyGoods>
    </div>
    <MyFooter @change="allFn" :arr="list"></MyFooter>
  </div>
</template>

<script>
import MyHeader from "./components/MyHeader"
import MyGoods from "./components/MyGoods"
import MyFooter from "./components/MyFooter"
export default {
  data() {
    return {
      //1.0请求数据
      //1.1新建空数组接收数据
      list: [],
    }
  },
  //1.2调用接口
  created() {
    this.$axios({
      url: "/api/cart",
    }).then((res) => {
      console.log(res)
      this.list = res.data.list
    })
  },
  components: {
    MyHeader,
    MyGoods,
    MyFooter,
  },
  methods: {
    allFn(val) {
      this.list.forEach((obj) => (obj.goods_state = val))
    },
  },
}
</script>

<style scoped>
.main {
  padding-top: 45px;
  padding-bottom: 50px;
}
</style>
